#定义元素和操作元素的方法
from selenium.webdriver.common.by import By
import time
from Base.basePage import BasePage


class ShopCollectionPage(BasePage):

    #元素
    deleteBtn=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div[3]/div/div[3]/form/div[2]/button")
    searchText=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div[3]/div/div[3]/form/div[3]/table/thead/tr/th[2]/div/input")
    startTime=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div[3]/div/div[3]/form/div[3]/table/thead/tr/th[3]/div/div[2]/input[1]")
    endTime=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div[3]/div/div[3]/form/div[3]/table/thead/tr/th[3]/div/div[2]/input[2]")
    detail=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div[3]/div/div[3]/form/div[3]/table/tbody/tr/td[4]/button[1]")
    detailPage=(By.XPATH,"/html/body/div[21]/div/div[1]/h4")
    refuseDetail=(By.XPATH,"/html/body/div[21]/div/div[1]/span")
    deleteOne=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div[3]/div/div[3]/form/div[3]/table/tbody/tr/td[4]/button[2]")
    deletePage=(By.XPATH,"/html/body/div[22]/div/div[1]")
    refuseDelete=(By.XPATH,"/html/body/div[22]/div/div[3]/span[1]")
    paginationText=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div[3]/div/div[3]/div[2]/ul/span[1]/input")
    pagination=(By.XPATH,"/html/body/div[1]/div[1]/div[3]/div[3]/div/div[3]/div[2]/ul/li[4]")


    #操作元素的方法
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        self.url = "https://d2.shopxo.vip/shop-shopfavor-index.html"

    def open(self,cookie):
        """打开店铺收藏页面"""
        self.driver.get(self.url)
        self.driver.add_cookie(cookie_dict=cookie)
        self.wait_for_element(self.deleteBtn)
        return self

    def is_on_order_page(self):
        """检查是否在商品收藏页面"""
        return "店铺收藏" in self.driver.title

    def click_detail_and_correct(self):
        """点击详情并确认"""
        self.click_element(self.detail)
        self.is_element_present(self.detailPage)
        self.click_element(self.refuseDetail)
        return self

    def click_delete_and_correct(self):
        """点击删除并确认"""
        self.click_element(self.deleteOne)
        self.is_element_present(self.deletePage)
        self.click_element(self.refuseDelete)

    def click_pagination_and_correct(self):
        """点击分页并确认"""
        self.input_text(self.paginationText, 1)
        current_page = self.pagination.text
        self.click_element(self.pagination)
        new_page = self.pagination.text
        assert current_page + 1 == new_page
        return self


